﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class UserDAO : CommonDAO
    {
        private string sql_getUserByNameAndPwd = "select UserID, RoleID from Users where UserName=@UserName and Password=@Password";
        private string table_user = "Users";
        private string sql_getAdmin = "SELECT * FROM Users WHERE UserID = @UserID and RoleID = '1'";

        public UserDAO()
            : base()
        {

        }

        // @StudentID
        // @StudentPwd
        public DataSet getUserByNameAndPwd(string strUserName, string password)
        {
            SqlCommand cmd = this.getCommand(sql_getUserByNameAndPwd);
            cmd.Parameters.Add("@UserName", SqlDbType.NChar, 20).Value = strUserName;
            cmd.Parameters.Add("@Password", SqlDbType.NChar, 20).Value = password;
            return this.executeCommand(cmd, table_user);
        }

        public bool isAdministrator(string userId)
        {
            SqlCommand cmd = this.getCommand(sql_getAdmin);
            cmd.Parameters.Add("@UserID", SqlDbType.VarChar, 10).Value = userId;
            return (this.executeCommand(cmd, table_user).Tables[0].Rows.Count > 0);
        }
    }
}
